package com.miaomaster.service;


import com.miaomaster.UserService;

import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService(version = "1.0")
public class UserServiceImpl implements UserService {


    @Override
    public String getUser() {
        return "miao1.0";
    }

    // 服务端流
    @Override
    public void sayHelloServiceStream(String name, StreamObserver<String> response) {

        response.onNext("sevice," + name);
        response.onNext("sevice," + name);

        response.onCompleted();
    }

    @Override
    public StreamObserver<String> sayHelloStream(StreamObserver<String> response) {

        return new StreamObserver<String>() {
            @Override
            public void onNext(String data) {
                System.out.println("服务端接收到的消息" + data);

                // 处理客户端传来的数据

                response.onNext("服务端返回的消息" + data);
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onCompleted() {
                System.out.println("服务端接收完毕");
            }
        };

    }
}
